/*******************************************************************************
 * PushButton Engine
 * Copyright (C) 2009 PushButton Labs, LLC
 * For more information see http://www.pushbuttonengine.com
 * 
 * This file is licensed under the terms of the MIT license, which is included
 * in the License.html file at the root directory of this SDK.
 ******************************************************************************/
package com.pblabs.engine.core
{
   import com.pblabs.engine.PBE;
   import com.pblabs.engine.debug.Logger;
   
   import flash.events.StatusEvent;
   import flash.net.LocalConnection;
   import flash.utils.Dictionary;
   import flash.utils.describeType;
   import flash.utils.getDefinitionByName;

   /**
    * 导入项目中未被引用的类
	* 保证程序编译时，这些类会被编译到
    */
   public class SchemaGenerator
   {
      /**
       * The singleton instance.
       */
      public static function get instance():SchemaGenerator
      {
         if (!_instance)
            _instance = new SchemaGenerator();
         
         return _instance;
      }
      
      private static var _instance:SchemaGenerator = null;
      
      public function SchemaGenerator()
      {
         // need these built in flash classes - there's probably more we should have
         addClassName("flash.geom.Point");
         addClassName("flash.geom.Rectangle");
         addClassName("Array");
         addClassName("flash.utils.Dictionary");
         addClassName("int");
         addClassName("uint");
         addClassName("Number");
         addClassName("Boolean");
         addClassName("String");
      }
      
      /**
       * Adds a class to be included in the schema. The TypeReference class automatically
       * adds classes it is given.
       */
      public function addClass(className:String, classObject:Class):void
      {
         _classes[className.replace("::", ".")] = classObject;
      }
      
      /**
       * Adds a class to be included in the schema.
       */
      public function addClassName(className:String):void
      {
         addClass(className, getDefinitionByName(className) as Class);
      }
	  
	  /**
	   * 
	   * @return A dictionary of Registered types. With keys as
	   * class names and values as class definitions
	   * 
	   */	  
	  public function getRegisteredTypes():Dictionary
	  {
		  return _classes;
	  }
      
      private var _failed:Boolean = false;
      private var _classes:Dictionary = new Dictionary();
      private var _connection:LocalConnection;
   }
}